<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<meta charset="utf-8">

<nav class="header navbar navbar-expand-lg navbar-light bg-white py-2 border-bottom ">
    <div class="container align-items-center">
        <!-- 网站品牌 -->
        <a class="logo navbar-brand fw-bold me-3" href="${pageContext.request.contextPath}/">${systemName}</a>

        <!-- 搜索框 -->
        <div class="flex-grow-1 mx-4 d-flex align-items-center" style="max-width: 600px;">
            <form action="${pageContext.request.contextPath}/client/product?method=search" method="post" class="w-100 my-0">
<%--                <input type="hidden" name="m" value="search">--%>
                <div class="input-group" style="height: 38px;">
                    <input class="form-control border-end-0"
                           type="search"
                           name="keyword"
                           placeholder="搜索..."
                           style="height: 100%; padding: 0.375rem 0.75rem;">
                    <button class="btn btn-danger px-3"
                            type="submit"
                            style="height: 100%;">
                        搜索
                    </button>
                </div>
            </form>
        </div>

        <!-- 用户操作区 -->
        <div class="d-flex align-items-center">
            <c:choose>
                <c:when test="${not empty sessionScope.loginUser}">
                    <nav class="nav bg-white ">
                        <a class="nav-link "
                           href="${pageContext.request.contextPath}/client/cart?method=index">
                            购物车
                        </a>
                        <a class="nav-link "
                           href="${pageContext.request.contextPath}/client/order?method=index">
                            我的订单
                        </a>
                    </nav>

                    <!-- 用户下拉菜单 -->
                    <div class="dropdown">
                        <a class="btn btn-outline-danger dropdown-toggle px-3 d-flex align-items-center"
                           href="#"
                           role="button"
                           data-bs-toggle="dropdown"
                           style="height: 38px;">
                                ${sessionScope.loginUser.username}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end" style="z-index: 1080">
                            <li><a class="dropdown-item"
                                   href="${pageContext.request.contextPath}/client/user?method=profile">
                                <i class="bi bi-person me-2"></i>个人中心</a></li>
                            <!-- 根据用户角色显示后台管理 -->
                            <c:if test="${loginUser.role == 1}">
                                <li><a class="dropdown-item"
                                       href="${pageContext.request.contextPath}/admin/product?method=viewList">
                                    <i class="bi bi-house-gear me-2"></i>后台管理</a></li>
                            </c:if>
                            <li>
                                <hr class="dropdown-divider">
                            </li>
                            <li><a class="dropdown-item" href="${pageContext.request.contextPath}/public?method=logout">
                                <i class="bi bi-box-arrow-right me-2"></i>退出登录</a></li>
                        </ul>
                    </div>
                </c:when>
                <c:otherwise>
                    <a href="${pageContext.request.contextPath}/public?method=viewLogin"
                       class="btn btn-outline-danger px-3 d-flex align-items-center"
                       style="height: 38px;">
                        登录/注册
                    </a>
                </c:otherwise>
            </c:choose>
        </div>
    </div>
</nav>
